
import { ALIOSS_URL } from '@env';
const manageCoverimage = (list:any[] , userInfo :any) => {
    let languageKey = 'cn'
    let { points: { free_times }, is_pro } = userInfo    
    list.forEach((item) => {
        const { charge_type } = item;
        let P = "";
        switch (item.type) {
            case "styler":
                P = "t";
                item.json_content.cover_image = fullImagePath(item.json_content.cover_image);
                break;
            case "scene":
                P = "t";
                item.json_content.cover_image = fullImagePath(item.json_content.cover_image);
                break;
            case "sticker":
                P = "t";
                item.json_content.cover_image_list.forEach((cover:any) =>{(cover.path = fullImagePath(cover.cover_image))});
                break;
            case "face_swap":
                P = "t";
                item.tpl_image_list.forEach((cover:any) => (cover.cat_image = fullImagePath(cover.cat_image)));
                break;
        }
        if (free_times > 0) {
            if (is_pro) {
                item.iconPath =
                    charge_type === "Free"
                        ? `${ALIOSS_URL}/img/static/index/free_${P}_${languageKey}.png`
                        : `${ALIOSS_URL}/img/static/index/vip_free_${P}_${languageKey}.png`;
                item.iconDesc =  `剩余${free_times}次`;
            } else {
                item.iconPath =
                    charge_type === "Free"
                        ? `${ALIOSS_URL}/img/static/index/free_${P}_${languageKey}.png`
                        : `${ALIOSS_URL}/img/static/index/vip_${P}_${languageKey}.png`;
                item.iconDesc = `剩余${free_times}次`;
            }
        } else {
            if (is_pro) {
                item.iconPath = `${ALIOSS_URL}/img/static/index/point_count_${P}_${languageKey}.png`;
                item.iconDesc = ``;
            } else {
                item.iconPath =
                    charge_type === "Free"
                        ? `${ALIOSS_URL}/img/static/index/point_count_${P}_${languageKey}.png`
                        : `${ALIOSS_URL}/img/static/index/vip_${P}_${languageKey}.png`;
                item.iconDesc =
                    charge_type === "Free" ?``: "会员专属";
            }
        }
    });
    return list
}


const fullImagePath = (path:string) => {
    return `${ALIOSS_URL}/img${path}`;
}

export {
    manageCoverimage,
    fullImagePath
}